import matplotlib.pyplot as plt
import matplotlib as mpl
class mat:
    def show(self):
        #grade = [8, 10, 15, 20, 25, 30, 35, 40, 46, 50, 55, 60, 66, 70, 78, 80, 89]
        grade=[]
        for i in self:
            grade.append(i[0])
        count = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        for i in grade:
            index = int(i / 10)
            count[index] = count[index] + 1
        miss=0
        min=100
        max=0
        nub=0
        amount=0
        avg=0
        for i in grade:
            if i<60:
                miss=miss+1
        for i in grade:
            if min>i:
                min=i
        for i in grade:
            if max<i:
                max=i
        for i in grade:
            nub=nub+1
            amount=amount+i
        avg=amount/nub
        print(miss,min,max,avg)


        plt.rcParams["font.sans-serif"] = ["KaiTi"]
        plt.rcParams["axes.unicode_minus"] = False

        plt.bar(range(10), count, align="center", color="steelblue", alpha=0.6)
        plt.ylim([0, 100])
        plt.title("成绩统计")
        plt.xticks(range(10),
                   ["0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100"])
        for x,y in enumerate(count):
            plt.text(x,y+3,y,ha="center")
        plt.text(10,100,"最低分"+str(min))
        plt.text(10, 90, "最高分" + str(max))
        plt.text(10, 80, "平均分" + str(avg))
        plt.text(10, 70, "不及格人数" + str(miss))

        plt.show()
    # def show_grade(self):
    #     test=[('数据库', 90), ('机组', 80), ('操作系统', 70), ('英语', 90), ('数学', 80), ('形势', 70)]
    #     name=[]
    #     grade=[]
    #     count=0
    #     for i in test:
    #         name.append(i[0])
    #         grade.append(i[1])
    #         count=count+1
    #     # plt.rcParams["font.sans-serif"] = ["KaiTi"]   #中文
    #     # plt.rcParams["axes.unicode_minus"] = False
    #     mpl.rcParams["font.sans-serif"] = ["SimHei"]  # 展示中文字体
    #     mpl.rcParams["axes.unicode_minus"] = False  # 处理负刻度值
    #     print(count)
    #     grades=[grade]
    #
    #     plt.table(cellText=grades,colLabels=name,rowLoc="center")
    #     plt.title("简单图形")
    #     plt.figure(dpi=80)
    #     plt.show()

